<template>
  <div id="order-loglist">
    <el-form :model="orderLogForm" ref="orderLogForm" class="orderLogForm" :inline="true" size="mini">
      <el-form-item label="订单ID">
        <el-input v-model="orderLogForm.orderCode" placeholder="请输入订单ID"></el-input>
      </el-form-item>
      <el-form-item label="操作时间" class="order-time">
        <el-row>
          <el-col :span="11" class="time-width">
            <el-date-picker
              v-model="orderLogForm.startTime"
              type="datetime"
              placeholder="选择开始日期"
              default-time="00:00:00">
            </el-date-picker>
          </el-col>
          <el-col :span="1" class="time-span">~</el-col>
          <el-col :span="11" class="time-width">
            <el-date-picker
              v-model="orderLogForm.endTime"
              type="datetime"
              placeholder="选择结束日期"
              default-time="23:59:59">
            </el-date-picker>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="操作人">
        <el-input v-model="orderLogForm.userName" placeholder="请输入操作人"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-select clearable v-model="orderLogForm.type" placeholder="请选择操作类型">
          <el-option v-for="(item, index) in typeList"
                     :key="item.id"
                     :label="item.name"
                     :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-button type="primary" size="small" @click="search(1)">搜索</el-button>
    </el-form>

    <el-table
      class="style-a"
      :data="tableData"
      size="small"
      border
      style="width:100%"
      v-loading.body="loadingOrderList" element-loading-text="Loading">
      <el-table-column
        label="订单ID"
        align="center"
        prop="orderCode"
        min-width="120">
      </el-table-column>
      <el-table-column
        label="产品名称"
        align="center"
        prop="productName"
        min-width="150">
      </el-table-column>
      <el-table-column
        label="操作时间"
        prop="cTStr"
        align="center"
        min-width="140">
      </el-table-column>
      <el-table-column
        label="操作人"
        align="center"
        prop="cUStr"
        min-width="100">
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        min-width="200">
        <template slot-scope="scope" class="handle">
          <div>
            <p class="p-content">{{scope.row.content}}</p>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @current-change="handleCurrentChange1"
      :current-page="currentPage"
      :page-sizes="[20]"
      :page-size="20"
      layout="total, prev, pager, next, jumper"
      :total="totalSize">
    </el-pagination>
  </div>
</template>
<script>
  import { getOrderRecordList, getOrderRecordType } from '@/api/orderLogList'
  export default {
    data() {
      return {
        orderLogForm: {
          scenicName: null,
          userName: null,
          startTime: null,
          endTime: null,
          type: null
        },
        typeList: [],
        currentPage: 1,
        totalSize: null,
        tableData: [],
        loadingOrderList: false
      }
    },
    created() {
      this.getOrderLogTypeList()
      this.getOrderLogList()
    },
    methods: {
      search() {
        this.currentPage = 1
        this.getOrderLogList()
      },
      handleCurrentChange1(val) {
        this.currentPage = val
        this.getOrderLogList(val)
      },
      getOrderLogTypeList() {
        getOrderRecordType().then(res => {
          let data = res.data
          if (data.errorCode === 'E_000') {
            this.typeList = data.body
          }
        })
      },
      getOrderLogList() {
        this.loadingOrderList = true
        let params = {
          startTime: new Date(this.orderLogForm.startTime).getTime() || null,
          endTime: new Date(this.orderLogForm.endTime).getTime() || null,
          pageNumber: this.currentPage,
          pageSize: 20,
          type: this.orderLogForm.type,
          orderCode: this.orderLogForm.orderCode || null,
          userName: this.orderLogForm.userName || null
        }
        getOrderRecordList(params).then(res => {
          let data = res.data
          this.loadingOrderList = false
          if (data.errorCode === 'E_000') {
            this.tableData = data.body.list
            this.totalSize = data.body.total
          }
        }).catch(() => {
          this.loadingOrderList = false
        })
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss">
  #order-loglist{
    .p-content{
      text-align: left;
    }
  }
</style>
